#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN=1000;
const int dx[]={-1, 0, 1, 0};
const int dy[]={0, 1, 0, -1};

struct node
{
	int x, y;
};

queue<node> q;
bool can[MAXN][MAXN][4];
bool vis[MAXN][MAXN];
int N, M;

void bfs(node st)
{
	while (!q.empty()) q.pop();
	vis[st.x][st.y]=true; q.push(st);
	while (!q.empty())
	{
		node tmp, now=q.front(); q.pop();
		for (int i=0; i<4; i++)
		{
			if (!can[now.x][now.y][i]) continue;
			tmp.x=now.x+dx[i];
			tmp.y=now.y+dy[i];
			if (vis[tmp.x][tmp.y]) continue;
			vis[tmp.x][tmp.y]=true;
			q.push(tmp);
		}
	}
}

int main()
{
	while (scanf("%d", &N)==1)
	{
		memset(can, 1, sizeof(can));
		for (int i=1; i<2*N; i++)
		{
			int x=i, y=(i&1)?1:2;
			getchar();
			for (int j=0; j<N; j++, y+=2)
			{
				char c=getchar();
				if (c=='H') can[x-1][y-1][2]=can[x-1][y][2]=can[x][y-1][0]=can[x][y][0]=false;
				else can[x-1][y-1][1]=can[x][y-1][1]=can[x-1][y][3]=can[x][y][3]=false;
			}
		}
		M=2*N+1; N=2*N;
		for (int i=0; i<N; i++) can[i][0][3]=can[i][M-1][1]=false;
		for (int i=0; i<M; i++) can[0][i][0]=can[N-1][i][2]=false;
		int cnt=0;
		memset(vis, 0, sizeof(vis));
		for (int i=0; i<N; i++)
			for (int j=0; j<M; j++)
			{
				if (vis[i][j]) continue;
				bfs((node){i, j}); cnt++;
			}
		printf("%d\n", cnt-1);
	}
	return 0;
}
